# -*- coding: utf-8 -*-
from flask import Flask
from pymongo import MongoClient
from .modules import (funcSearch, fileSearch, summarizefn, uploadfile,
                      fileSearch_template, uploadfile_local, autoTake)
from .config import Config
from flasgger import Swagger

def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    # 初始化Swagger
    swagger = Swagger(app)

    # 配置 MongoDB
    mongo_uri = "mongodb://localhost:27017/mydatabase"  # 替换为你的MongoDB URI
    client = MongoClient(mongo_uri)
    app.db = client.get_default_database()  # 获取默认数据库（在这里是 'mydatabase'）

    # 注册模块
    app.register_blueprint(funcSearch.bp)
    app.register_blueprint(fileSearch.bp)
    app.register_blueprint(fileSearch_template.bp)
    app.register_blueprint(summarizefn.bp)
    app.register_blueprint(uploadfile.bp)
    app.register_blueprint(autoTake.bp)
    app.register_blueprint(uploadfile_local.bp)

    return app
